package com.zczc.tagmanagement.common;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 16:28 2018-12-10
 * @Modify by:
 */

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import org.springframework.http.HttpStatus;

/**
 * 通用的实体返回类
 */
@ApiModel(value = "通用实体返回类" , description = "用于所有接口的通用返回数据")
@JsonInclude(Include.NON_NULL)
public class Response implements Serializable {

  @ApiModelProperty("返回消息的序列号")
  private String id;

  @ApiModelProperty("返回消息的请求状态，参考httpstatus")
  private int code;

  @ApiModelProperty("返回的基本信息")
  private String msg;

  @ApiModelProperty("返回的数据信息")
  private Object data;

  @ApiModelProperty("返回数据的时间")
  @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss",
      timezone = "GMT+8"
  )
  private Date date;

  //请求成功
  public static Response suc(Object data){
    return new Response(HttpStatus.OK.value(),"请求成功",data);
  }

  //坏的请求
  public static Response badParam(String msg){
    return new Response(HttpStatus.BAD_REQUEST.value(),msg);
  }

  //不允许的请求
  public static Response notAllow(String msg){
    return new Response(HttpStatus.FORBIDDEN.value(),msg);
  }

  //内部服务器错误
  public static Response error(String msg){
    return new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(),msg);
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  public Date getDate() {
    return date;
  }

  public void setDate(Date date) {
    this.date = date;
  }

  public Response() {
  }

  public Response(int code, String msg) {
    this.code = code;
    this.msg = msg;
  }

  public Response(int code, String msg, Object data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }
}
